module("PlayerUI", package.seeall)

function create()
	local self = ccs.GUIReader:getInstance():widgetFromJsonFile("res/UI/MainUI/PlayerUI.ExportJson")
	init(self)
	return self
end

function onButtonCloseClick(self)
	self:removeFromParent()
end

function onButtonLogoutClick(self)
	SceneManager.switchToScene(LoginScene.create())
end

function onButtonQuitClick(self)
	cc.Director:getInstance():popScene()
end

function init(self)
	local _panelMain = self:getChildByName("Panel_Main")
	local _buttonClose = _panelMain:getChildByName("Button_Close")
	local _buttonQuit = _panelMain:getChildByName("Button_Quit")
	local _buttonLogout = _panelMain:getChildByName("Button_Logout")

	_buttonClose:addTouchEventListener(
		function ( sender, eventType )
			if (eventType == ccui.TouchEventType.ended) then
				onButtonCloseClick(self)
			end
		end)

	_buttonLogout:addTouchEventListener(
		function ( sender, eventType)
			if (eventType == ccui.TouchEventType.ended) then
				onButtonLogoutClick(self)
			end
		end)

	_buttonQuit:addTouchEventListener(
		function ( sender, eventType)
			if (eventType == ccui.TouchEventType.ended) then
				onButtonQuitClick(self)
			end
		end)
end
